import numpy as np
import mathutils as mu
from numpy import linalg as LA
import graph_utils
from graph_utils import DyadFeaturesIndexLocator
import graphsim as gsim
import networkx as nx
import srw as srwM
from srw import SRW


def main():
    A = [ [0,1,0],
          [1,0,1],
          [0,1,0]
         ]
    A = np.array(A, dtype='float')
    G = nx.Graph(A)
    
#     print gsim.rwr(A, 0.5)
#     print nx.pagerank(G, 0.5)
    
    psi = PSI(3, 2)
    T = {}
    T[0] = [[2],[1]]
    srw = SRW(psi, T, A, 0.5)
    
    srw.optimize(10)
    print srwM.rwr(srw.get_P(0), 0, 0.5)
    print srwM.rwr(srw.get_P(1), 1, 0.5)
    print srwM.rwr(srw.get_P(2), 2, 0.5)

class PSI:
    def __init__(self, n_row, n_cols):
        self.X = np.random.random((n_row, n_cols))
        self.n_row = n_row
        self.n_cols = n_cols
    
    
    def get_feature_vec(self, node1_index, node2_index):
        """
        return the feature vector for the edge (node1, node2)
        """
        
        if ( (node1_index==0 and node2_index==1) or 
             (node1_index==1 and node2_index==0) ):
#             return self.X[0]
            return np.array([0.1, 0.2])
        elif ( (node1_index==0 and node2_index==2) or 
             (node1_index==2 and node2_index==0) ):
#             return self.X[1]
            return np.array([0.3, 0.4])
        elif ( (node1_index==1 and node2_index==2) or 
             (node1_index==2 and node2_index==1) ):
#             return self.X[2]
            return np.array([0.5, 0.6])
        else:
            print 'FUUUUUUUUUCKKKK'
        
    def num_feats(self):
        """
        returns the number of features
        """
        return self.n_cols













main()